<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var obj = {
        id: 1,
        name: "andy",
        msg: {
          age: 18,
        },
        color: ["666", "333"],
      };
      var o = {};
      function deepCopy(newobj, oldobj) {
        for (var k in oldobj) {
          var vall = oldobj[k];
          if (vall instanceof Array) {
            newobj[k] = [];
            deepCopy(newobj[k], vall);
          } else if (vall instanceof Object) {
            newobj[k] = {};
            deepCopy(newobj[k], vall);
          } else {
            newobj[k] = vall;
          }
        }
      }
      deepCopy(o, obj);
      console.log(o);
    </script>
  </body>
</html>
